package com.it.service.impl;

import com.it.vo.SecurityUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * TODO
 *
 * @author: Coke
 * @DateTime: 2023/11/08/20:16
 **/
@Service
public class UserServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername (String username) throws UsernameNotFoundException {
        // 判断用户名是否为空
        if (!StringUtils.hasText(username)) {
            throw new UsernameNotFoundException("用户名不存在!");
        }
        // 判断用户是否正确
        if (!username.equals("张三")) {
            throw new UsernameNotFoundException("用户名不正确！");
        }
        // 执行到这里 说明用户名不为空 并且 用户名正确
        return new SecurityUser();
    }
}
